import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PhoneTaskService {

    private final PhoneTaskQueueManager queueManager;

    @Autowired
    public PhoneTaskService(PhoneTaskQueueManager queueManager) {
        this.queueManager = queueManager;
        this.queueManager.startProcessing(); // 启动任务处理
    }

    public void addTask(String phoneNumber, Runnable task) {
        queueManager.addTask(phoneNumber, task, 0); // 正常优先级
    }

    public void addUrgentTask(String phoneNumber, Runnable task) {
        queueManager.addTaskWithHigherPriority(phoneNumber, task); // 插队任务
    }

    public void cancelTask(String phoneNumber, int taskId) {
        queueManager.cancelTask(phoneNumber, taskId); // 取消特定任务
    }

    public void cancelAllTasks(String phoneNumber) {
        queueManager.cancelAllTasks(phoneNumber); // 取消某个号码的所有任务
    }
}
